<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * 인기 스타 관리 컨트롤러
 */
class Artist extends CI_Controller {
	
	function __construct() {
		parent::__construct();

		$this->load->model('imbc/Artist_model', 'artist');
	}
	
	// Default
	function index() {
		redirect('imbc/artist/artist_list');
	}
	

	/*******************************************************************
	 * iMBC 프로그램 관리 리스트
	 *******************************************************************/
	function program_list() {
		log_message('debug', "@@@@ imbc/Artist::program_list()");
		
		$this->data['program_list'] = $this->artist->select_program_list();
		
		$this->load->view('imbc/program_list_v', $this->data);
	}
	
	
	/*******************************************************************
	 * iMBC 프로그램 추가
	 *******************************************************************/
	function program_register_ok() {
		log_message('debug', "@@@@ imbc/Artist::program_register_ok()");

		$program['program_id']   = $this->input->post('program_id', TRUE);
		$program['program_name'] = $this->input->post('program_name', TRUE);
		$program['type']         = $this->input->post('type', TRUE);
		$program['priority']     = $this->input->post('priority', TRUE);
		$program['story']        = $this->input->post('story', TRUE);
		$program['start_dt']     = $this->input->post('start_dt', TRUE);
		$program['end_dt']       = $this->input->post('end_dt', TRUE);
		$program['photo_url']    = $this->input->post('photo_url', TRUE);
		
		$this->artist->insert_program($program);
		
		redirect("/imbc/artist/program_list");
	}
	
	
	/*******************************************************************
	 * iMBC 프로그램 수정
	 *******************************************************************/
	function program_modify_ok() {
		log_message('debug', "@@@@ imbc/Artist::program_modify_ok()");

		$program['program_id']   = $this->input->post('program_id', TRUE);
		$program['program_name'] = $this->input->post('program_name', TRUE);
		$program['type']         = $this->input->post('type', TRUE);
		$program['priority']     = $this->input->post('priority', TRUE);
		$program['story']        = $this->input->post('story', TRUE);
		$program['start_dt']     = $this->input->post('start_dt', TRUE);
		$program['end_dt']       = $this->input->post('end_dt', TRUE);
		$program['use_yn']       = $this->input->post('use_yn', TRUE);
		$program['photo_url']    = $this->input->post('photo_url', TRUE);
		
		$this->artist->update_program($program);
		
		redirect("/imbc/artist/program_list");
	}
		
	
	/*******************************************************************
	 * iMBC 프로그램 삭제
	 *******************************************************************/
	function program_remove_ok() {
		log_message('debug', "@@@@ imbc/Artist::program_remove_ok()");
		
		$program_id  = $this->input->post('program_id');
		
		$this->artist->delete_program($program_id);
		echo "<script type='text/javascript'>alert('삭제완료');location.href='/imbc/artist/program_list';</script>";
	}



	
	/*******************************************************************
	 * iMBC 스타 관리 리스트
	 *******************************************************************/
	function artist_list() {
		log_message('debug', "@@@@ imbc/Artist::artist_list()");
		
		// 리스트
		$this->data['artist_list'] = $this->artist->select_artist_list();
		
		// 셀렉트 박스에 들어갈 값들
		$this->data['display_position_list'] = $this->artist->select_display_position_list();
		$this->data['program_list'] = $this->artist->select_program_list();
		
		$this->load->view('imbc/artist_list_v', $this->data);
	}

	
	/*******************************************************************
	 * iMBC 스타 검색 창
	 *******************************************************************/
	function search() {
		log_message('debug', "@@@@ imbc/Artist::search()");

		$search_keyword = $this->input->post('search_keyword', TRUE);
		if (!empty($search_keyword)) {
			$this->data['search_keyword'] = $search_keyword;
			$this->data['artist_list'] = $this->artist->select_artist_search_list($search_keyword);
		} else {
			$this->data['search_keyword'] = '';
		}
		
		$this->load->view('imbc/artist_search_pop_v', $this->data);
	}


	/*******************************************************************
	 * iMBC 스타 추가
	 *******************************************************************/
	function register_ok() {
		log_message('debug', "@@@@ imbc/Artist::register_ok()");

		$artist['position_id'] = $this->input->post('position_id', TRUE);
		$artist['program_id']  = $this->input->post('program_id', TRUE);
		$artist['artist_idx']  = $this->input->post('artist_idx', TRUE);
		$artist['priority']    = $this->input->post('priority', TRUE);
		$artist['role']        = $this->input->post('role', TRUE);
		$artist['photo_url']   = $this->input->post('photo_url', TRUE);
		
		$this->artist->insert_artist($artist);
		
		redirect("/imbc/artist/artist_list");
	}


	/*******************************************************************
	 * iMBC 스타 수정
	 *******************************************************************/
	function modify_ok() {
		log_message('debug', "@@@@ imbc/Artist::modify_ok()");

		$artist['position_id'] = $this->input->post('position_id', TRUE);
		$artist['program_id']  = $this->input->post('program_id', TRUE);
		$artist['artist_idx']  = $this->input->post('artist_idx', TRUE);
		$artist['priority']    = $this->input->post('priority', TRUE);
		$artist['role']        = $this->input->post('role', TRUE);
		$artist['photo_url']   = $this->input->post('photo_url', TRUE);
		$artist['use_yn']      = $this->input->post('use_yn', TRUE);
		
		$this->artist->update_artist($artist);
		
		redirect("/imbc/artist/artist_list");
	}
	
	
	/*******************************************************************
	 * iMBC 스타 삭제
	 *******************************************************************/
	function remove_ok() {
		log_message('debug', "@@@@ imbc/Artist::remove_ok()");
		
		$position_id = $this->input->post('position_id');
		$program_id  = $this->input->post('program_id');
		$artist_idx  = $this->input->post('artist_idx');
		
		$this->artist->delete_artist($position_id, $program_id, $artist_idx);
		echo "<script type='text/javascript'>alert('삭제완료');location.href='/imbc/artist/artist_list';</script>";
	}

}


/* End of file artist.php */
/* Location: ./application/controllers/imbc/artist.php */